namespace Xsxiaosa.Net
{
    using System;
    using System.Runtime.CompilerServices;

    public class FtpItem
    {
        // Events
        public static  event FtpItemParseEventHandler ItemParse;

        // Methods
        public FtpItem(string filename, long size, FtpItemType type) : this(filename, size, type, DateTime.Now, null)
        {
        }

        public FtpItem(string filename, long size, FtpItemType type, DateTime lastModified, string symlinkPath)
        {
            this._system = FtpItemSystem.Unknown;
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (filename.Length == 0)
            {
                throw new ArgumentException(Xsxiaosa.Net.Messages.GetString("ArgumentEmptyString"), filename);
            }
            if (size < ((long) 0))
            {
                throw new ArgumentOutOfRangeException("size");
            }
            if (!Enum.IsDefined(typeof(FtpItemType), type))
            {
                throw new ArgumentOutOfRangeException("type");
            }
            if ((type == FtpItemType.Symlink) && (symlinkPath == null))
            {
                throw new ArgumentNullException("symlinkPath");
            }
            this._filename = filename;
            this._size = size;
            this._type = type;
            this._lastModified = lastModified;
            this._symlinkPath = symlinkPath;
        }

        internal FtpItem(FtpItemSystem system, string filename, long size, FtpItemType type, DateTime lastModified, string symlinkPath) : this(filename, size, type, lastModified, symlinkPath)
        {
            this._system = system;
        }

        public static FtpItem Parse(string rawLine)
        {
            FtpItem item1 = FtpListParse.ParseListLine(rawLine);
            if (FtpItem.ItemParse == null)
            {
                return item1;
            }
            FtpItemParseEventArgs args1 = new FtpItemParseEventArgs(rawLine, item1);
//jyj modify            FtpItem.ItemParse.Invoke(null, args1);
			FtpItem.ItemParse(null, args1);
            if (args1.Item != item1)
            {
                args1.Item.ItemType = FtpItemSystem.Custom;
            }
            return args1.Item;
        }


        // Properties
        public bool IsDirectory
        {
            get
            {
                return (this._type == FtpItemType.Directory);
            }
        }

        public bool IsFile
        {
            get
            {
                return (this._type == FtpItemType.File);
            }
        }

        public bool IsSymlink
        {
            get
            {
                return (this._type == FtpItemType.Symlink);
            }
        }

        internal FtpItemSystem ItemType
        {
            get
            {
                return this._system;
            }
            set
            {
                this._system = value;
            }
        }

        public DateTime Modified
        {
            get
            {
                return this._lastModified;
            }
        }

        public string Name
        {
            get
            {
                return this._filename;
            }
        }

        public long Size
        {
            get
            {
                return this._size;
            }
        }

        public string SymlinkPath
        {
            get
            {
                return this._symlinkPath;
            }
        }

        public FtpItemType Type
        {
            get
            {
                return this._type;
            }
        }


        // Fields
        private string _filename;
        private DateTime _lastModified;
        private long _size;
        private string _symlinkPath;
        private FtpItemSystem _system;
        private FtpItemType _type;
    }}

